home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / xvars.c < prev   
C/C++ Source or Header  |  1993-07-08  |  6KB  |  175 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                           *
  4. *  Date        : Nov 92                                                   *
  5. *  Last Update : April 92                                                 *
  6. *                                                                         *
  7. *  Module      : xvars                                                    *
  8. *                                                                         *
  9. *  Function    : Athena Widgets for handling definitions of a unit        *
  10. *                                                                         *
  11. *  Export :                                                               *
  12. *                                                                         *
  13. *                                                                         *
  14. **************************************************************************/
  15.  
  16. /****************************************************************************
  17. *                                                                           *
  18. *    list :  vars                                                           *
  19. *                                                                           *
  20. ****************************************************************************/
  21.  
  22. #include "xglobal.h"      /* import vars, VarCount */
  23. #include "Definitions.h"  
  24. #include <Idents.h>
  25.  
  26. extern char * malloc();    /* no include file specified */
  27.  
  28. Widget vars_popup, vars_menu;
  29.  
  30. /****************************************************************************
  31. *                                                                           *
  32. *   VarButton: is called when button is released                            *
  33. *              pops vars_popup up if it is button3                          *
  34. *                                                                           *
  35. ****************************************************************************/
  36.  
  37. void VarButton (w, client_data, event)
  38. Widget w;
  39. XtPointer client_data;
  40. XEvent *event;
  41. {
  42.   if (event->xbutton.button == Button3)
  43.     {   XtVaSetValues (vars_popup, XtNx, event->xbutton.x_root, 
  44.                                    XtNy, event->xbutton.y_root, NULL); 
  45.         XtPopup (vars_popup, XtGrabNonexclusive);
  46.     }
  47. }
  48.  
  49. /****************************************************************************
  50. *                                                                           *
  51. *   For a given declaration tree the position in the source                 *
  52. *   will be hightlighted (called by unit- and var-select                    *
  53. *                                                                           *
  54. ****************************************************************************/
  55.  
  56. void show_selected_decl (); /* imported from units.c */
  57.  
  58. void VarSelect (w, client_data, call_data)
  59. Widget w;
  60. XtPointer  client_data;
  61. XawListReturnStruct *call_data;
  62.  
  63. { XawListReturnStruct *unit_data;
  64.   tEntries Declarations;
  65.   tIdent Ident;
  66.   tObject Decl;
  67.  
  68.   if (call_data->list_index >= VarCount)
  69.       printf ("No function \n");
  70.    else
  71.     { Declarations = UnitDeclarations;
  72.  
  73.       /* now search the entry for var */
  74.  
  75.       Ident = MakeIdent (call_data->string, strlen (call_data->string));
  76.       Decl = GetDeclEntry (Ident, Declarations);
  77.  
  78.       if (Decl == NoObject)
  79.          printf ("Entry for %s not found \n", call_data->string);
  80.        else
  81.          { WriteTree (stdout, Decl->Object.decl);
  82.            show_selected_decl (Decl->Object.decl);
  83.          }
  84.     }
  85. }
  86.  
  87. /* predefined list of unit items : must not be empty  */
  88.  
  89. static String var_items [] =
  90.    { "<list_of_vars>" };
  91.  
  92. void VarMenuSelect (w, client_data, garbage)
  93. Widget w;
  94. XtPointer client_data;
  95. XtPointer garbage;  /* call_data */
  96. {   Widget menu, father;
  97.     char *name;
  98.     int i = (int) client_data;
  99.     printf ("This function will be realized in a future version\n");
  100.     XtPopdown (vars_popup);
  101. }
  102.  
  103. void init_vars (parent)
  104. Widget parent;
  105. { int n;
  106.   Arg args[10];
  107.   Widget entry;
  108.   int x, y;
  109.  
  110.   n = 0;
  111.   XtSetArg (args[n], XtNnumberStrings, 1);  n++;
  112.   XtSetArg (args[n], XtNlist, var_items);  n++;
  113.   XtSetArg (args[n], XtNdefaultColumns, 1);  n++;
  114.   XtSetArg (args[n], XtNcolumnSpacing, 15);  n++;
  115.  
  116.   vars = XtCreateManagedWidget(
  117.           "vars",                         /* widget name */
  118.           listWidgetClass,                 /* widget class */
  119.           parent,                          /* parent widget*/
  120.           args, n);                        /* varargs list */
  121.  
  122.   VarCount = 0;
  123.  
  124.   XtAddCallback(vars, XtNcallback, VarSelect, 0);
  125.  
  126.   XtAddEventHandler (vars, ButtonReleaseMask, FALSE, VarButton, 0);
  127.  
  128.   vars_popup =  XtCreatePopupShell ("VarMenu", transientShellWidgetClass,
  129.                             vars, NULL, 0);
  130.  
  131.   vars_menu =  XtCreateManagedWidget ("varmenu", boxWidgetClass,
  132.                             vars_popup, NULL, 0);
  133.  
  134.   entry = XtCreateManagedWidget ("Show Definitions",
  135.                   commandWidgetClass, vars_menu, NULL, 0);
  136.   XtAddCallback (entry, XtNcallback, VarMenuSelect, (XtPointer) 1);
  137.   entry = XtCreateManagedWidget ("Show Uses",
  138.                   commandWidgetClass, vars_menu, NULL, 0);
  139.   XtAddCallback (entry, XtNcallback, VarMenuSelect, (XtPointer) 2);
  140. }
  141.  
  142. void show_vars (Declarations)
  143. tDefinitions Declarations;
  144.  
  145. {  tObject Elem;
  146.    char Item[150];
  147.    int i; 
  148.    String H;
  149.  
  150.    VarCount = 0;
  151.    while (Declarations->Kind != kENTRY_EMPTY )
  152.       { Elem = Declarations->ENTRY_LIST.Elem;
  153.         GetString (Elem->Object.ident, Item);
  154.         if (VarCount == MaxVarItems)
  155.            printf ("ERROR: maximal number of Variable Items reached\n");
  156.         VarItems[VarCount] =  malloc (strlen (Item) + 1);
  157.         strcpy (VarItems[VarCount],Item);
  158.         VarCount += 1;
  159.         Declarations = Declarations->ENTRY_LIST.Next;
  160.       }
  161.  
  162.    /* There are VarCount Entries */
  163.  
  164.    /* reverse the list: 0 <-> N-1, 1 <-> N-2, ... */
  165.  
  166.    for (i=0;i<VarCount/2;i++)
  167.      { H = VarItems[i];
  168.        VarItems[i] = VarItems[VarCount-1-i];
  169.        VarItems[VarCount-1-i] = H;
  170.      }
  171.  
  172.    XawListChange (vars, VarItems, VarCount, -1, TRUE);
  173.  
  174. } /* show_vars */
  175.